# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library")
load("@org_tensorflow//tensorflow/core/platform:build_config.bzl", "tf_proto_library")

package(
    default_visibility = ["//visibility:public"],
)

proto_library(
    name = "access_policy_proto",
    srcs = ["access_policy.proto"],
    deps = [
        "@oak//proto/attestation:reference_value_proto",
    ],
)

cc_proto_library(
    name = "access_policy_cc_proto",
    deps = [":access_policy_proto"],
)

proto_library(
    name = "verification_record_proto",
    srcs = ["verification_record.proto"],
    deps = [
        ":access_policy_proto",
        "@oak//proto/attestation:endorsement_proto",
        "@oak//proto/attestation:evidence_proto",
    ],
)

cc_proto_library(
    name = "verification_record_cc_proto",
    deps = [":verification_record_proto"],
)

proto_library(
    name = "blob_header_proto",
    srcs = ["blob_header.proto"],
)

cc_proto_library(
    name = "blob_header_cc_proto",
    deps = [":blob_header_proto"],
)

proto_library(
    name = "aggregation_client_payload_proto",
    srcs = ["aggregation_client_payload.proto"],
)

cc_proto_library(
    name = "aggregation_client_payload_cc_proto",
    deps = [":aggregation_client_payload_proto"],
)

proto_library(
    name = "ledger_proto",
    srcs = ["ledger.proto"],
    deps = [
        "@com_google_protobuf//:duration_proto",
        "@com_google_protobuf//:timestamp_proto",
        "@oak//proto/attestation:endorsement_proto",
        "@oak//proto/attestation:evidence_proto",
        "@oak//proto/micro_rpc:options_proto",
    ],
)

cc_proto_library(
    name = "ledger_cc_proto",
    deps = [":ledger_proto"],
)

proto_library(
    name = "pipeline_transform_proto",
    srcs = ["pipeline_transform.proto"],
    deps = [
        "@com_google_protobuf//:any_proto",
        "@oak//proto/micro_rpc:options_proto",
    ],
)

proto_library(
    name = "confidential_transform_proto",
    srcs = ["confidential_transform.proto"],
    deps = [
        "@com_google_googleapis//google/rpc:status_proto",
        "@com_google_protobuf//:any_proto",
    ],
)

cc_proto_library(
    name = "confidential_transform_cc_proto",
    deps = [":confidential_transform_proto"],
)

cc_grpc_library(
    name = "confidential_transform_cc_grpc",
    srcs = [":confidential_transform_proto"],
    generate_mocks = True,
    grpc_only = True,
    deps = [":confidential_transform_cc_proto"],
)

# Using tf_proto_library to get dependencies to TF protos built correctly.
tf_proto_library(
    name = "tff_worker_configuration_proto",
    srcs = ["tff_worker_configuration.proto"],
    protodeps = [
        "@org_tensorflow//tensorflow/core:protos_all",
    ],
)

# Allowing to refer to the cc library generated by the rule above in usual way:
alias(
    name = "tff_worker_configuration_cc_proto",
    actual = "tff_worker_configuration_proto_cc",
)

alias(
    name = "tff_worker_configuration_py_proto",
    actual = "tff_worker_configuration_proto_py",
)

cc_proto_library(
    name = "pipeline_transform_cc_proto",
    deps = [":pipeline_transform_proto"],
)

cc_grpc_library(
    name = "pipeline_transform_cc_grpc",
    srcs = [":pipeline_transform_proto"],
    generate_mocks = True,
    grpc_only = True,
    deps = [":pipeline_transform_cc_proto"],
)

py_proto_library(
    name = "pipeline_transform_py_proto",
    deps = [":pipeline_transform_proto"],
)

py_grpc_library(
    name = "pipeline_transform_py_grpc",
    srcs = [":pipeline_transform_proto"],
    deps = [":pipeline_transform_py_proto"],
)

# Use tf_proto_library to build the dependencies correctly
tf_proto_library(
    name = "sql_query_proto",
    srcs = ["sql_query.proto"],
    protodeps = ["//fcp/protos:plan_proto"],
)

# Allowing to refer to the cc library generated by the rule above in usual way:
alias(
    name = "sql_query_cc_proto",
    actual = "sql_query_proto_cc",
)

alias(
    name = "sql_query_py_proto",
    actual = "sql_query_proto_py",
)

java_lite_proto_library(
    name = "sql_query_java_proto_lite",
    deps = [":sql_query_proto"],
)

proto_library(
    name = "tff_config_proto",
    srcs = ["tff_config.proto"],
    deps = [
        "@org_tensorflow_federated//tensorflow_federated/proto/v0:executor_proto",
    ],
)

cc_proto_library(
    name = "tff_config_cc_proto",
    deps = [":tff_config_proto"],
)

proto_library(
    name = "agg_core_container_config_proto",
    srcs = ["agg_core_container_config.proto"],
)

cc_proto_library(
    name = "agg_core_container_config_cc_proto",
    deps = [":agg_core_container_config_proto"],
)
